package com.hrt.datasender.datacollect.drive.weigeng;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.frame.FrameDecoder;

public class WeiGengFrameDecode extends FrameDecoder {
    private final int msgMinLength = 64;

    @Override
    protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
        
        /**
         * 按约定，必须要有64字节
         */
        if (buffer.readableBytes() < msgMinLength) {
            return null;
        }

        byte[] decoded = new byte[msgMinLength];
        buffer.readBytes(decoded);

        return decoded;
    }

}
